export class BaseTableTdView {

    _pubsub = null;

    constructor(pubsub) {
        this.init(pubsub)

    }

    //========================== 接口方法 ==========================

    render(prop) {
        console.log('渲染', prop)
        let table = document.getElementById('table');
        for (let i = 0; i < prop.length; i++) {
            console.log(prop[i])

            let tr = this.createElement('tr');
            for (const [k, v] of prop[i].property) {
                let td = this.createElement('td');
                // console.log(td)
                td.innerText = v;
                tr.appendChild(td);
            }
            table.appendChild(tr);
        }
    }


    //========================== 初始方法 ==========================

    init(pubsub) {
        
        this.pubsub = pubsub;

        this.subscriber()
    }

    //========================== 内部方法 ==========================

    createElement(element) {
        return document.createElement(element);
    }

    //========================== 事件订阅 ==========================

    subscriber() {
        this.pubsub.subscriber('change-product', this.render.bind(this));
    }
}